package com.pactera.madp.cp.controller.oms.taskpublish;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.taskpublish.ReadEmployeeDTO;
import com.pactera.madp.cp.api.dto.taskpublish.TaskAddDTO;
import com.pactera.madp.cp.api.dto.taskpublish.TaskQueryDTO;
import com.pactera.madp.cp.api.entity.taskpublish.TaskEntity;
import com.pactera.madp.cp.api.vo.taskpublish.TaskDetailVO;
import com.pactera.madp.cp.api.vo.taskpublish.TaskQueryVO;
import com.pactera.madp.cp.common.constant.TaskPublsih;
import com.pactera.madp.cp.service.ITaskPublishService;
import com.pactera.madp.cp.service.ITaskReadCountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @date: 2021/8/10 15:37
 * @description:
 */
@RestController
@AllArgsConstructor
@RequestMapping("/taskpublish")
@Api(value = "taskpublish", tags = "任务发布")
public class TaskPublishController {

    @Autowired
    private ITaskPublishService taskPublishService;
    @Autowired
    private ITaskReadCountService taskReadCountService;

    @SysLog("任务发布-新建")
    @PostMapping
    @ApiOperation(value = "新建任务")
    public R saveTask(@RequestBody TaskAddDTO taskAddDTO){
        return R.ok(taskPublishService.createTask(taskAddDTO));}

    @SysLog("任务发布-发布")
    @PostMapping("/publish-on")
    @ApiOperation(value = "发布任务")
    public R publishTaskById(@RequestParam(value = "id")Integer id){
        TaskEntity taskEntity = new TaskEntity();
        taskEntity.setId(id);
        taskEntity.setStatus(Integer.valueOf(TaskPublsih.TASK_STATUS_PUBLISH_ON));
        taskPublishService.sendTaskToChatGroup(id);
        taskPublishService.updateById(taskEntity);
        return R.ok();
    }

    @GetMapping("/pagequery")
    @ApiOperation(value = "分页查询任务列表")
    public R<Page<List<TaskQueryVO>>> getTaskList(Page page, TaskQueryDTO dto){return taskPublishService.pageQuery(page,dto);}

    @GetMapping("/look-up")
    @ApiOperation(value = "查看任务")
    public TaskDetailVO detailShow(Integer id){return taskPublishService.detailShow(id);}

    @SysLog("任务发布-保存已阅读成员")
    @PostMapping("/save-employee")
    @ApiOperation(value = "保存已阅读成员")
    public R saveReadEmployee(ReadEmployeeDTO dto){return taskReadCountService.saveEmployeeList(dto);}

    @GetMapping("/task-detail")
    @ApiOperation(value = "阅读统计")
    public R getTaskDetail(Integer id){return taskPublishService.getTaskReadDetail(id);}

}
